#pragma once

class CGraphic
{
public:
    enum HBITMAP_TYPE{
        HBITMAP_FULL,
        HBITMAP_HALF,
        HBITMAP_USER
    };

    CGraphic();
    CGraphic(HDC hdc, int nWidth, int nHeight);
    virtual ~CGraphic(void);

    BYTE* LockBits();
    void UnlockBits();

    static void BitBlt(
        HDC hdc, RECT& rt, const void * pBits, int nWidth, int nHeight, int nBitPixel);

    COLORREF GetPixel(int nX, int nY);
    COLORREF SetPixel(int nX, int nY, COLORREF clrNew);

    int GetStride();
    int GetWidth();
    int GetHeight();

    void Save(const TCHAR * pFileName);

    static int GetDIBColorCount(const BITMAPINFO * pDIB);
    static BOOL SaveDIBToFile(const TCHAR * pFileName, const BITMAPINFO * pBMI, const void * pBits);
    static void SaveHDCAsImage(const TCHAR * pFileName, HDC hdc);
    static void SaveHWNDAsImage(const TCHAR * pFileName, HWND hWnd);

    static void SaveDesktopAsImage(const TCHAR * pFileName);

private:
    BITMAPINFO m_bmpinfo;
    BYTE *m_pBits;
    HDC m_hdc;
    HDC m_hDesktop;
    HBITMAP m_hBmp;
    int m_nWidth;
    int m_nHeight;
    int m_nStride;
};


